#pragma once

#include <include\cef_resource_handler.h>
#include <include\cef_urlrequest.h>

class CCefHandler;
class CCefURLRequestClient;

class CCefResourceHandler : public CefResourceHandler
{
public:
	CCefResourceHandler();

	virtual bool ProcessRequest(CefRefPtr<CefRequest> request, CefRefPtr<CefCallback> callback) OVERRIDE;
	virtual void GetResponseHeaders(CefRefPtr<CefResponse> response, int64& response_length, CefString& redirectUrl) OVERRIDE;
	virtual void Cancel() OVERRIDE {}

	virtual bool ReadResponse(void* data_out, int bytes_to_read, int& bytes_read, CefRefPtr<CefCallback> callback) OVERRIDE;

public:
	CefRefPtr<CCefHandler> _clientHandler;
	CefRefPtr<CefBrowser> _browser;
	CefRefPtr<CefFrame> _frame;

	CefRefPtr<CefCallback> _responseHeadersReadyCallback;

	CefRefPtr<CCefURLRequestClient> _webRequestClient;
	CefRefPtr<CefURLRequest> _webRequest;

	std::string _content;

private:
	size_t _offset;

	IMPLEMENT_REFCOUNTING(CCefResourceHandler);
};

